<template>
    <div id="wxlogin"></div>
</template>

<script>
export default {
	data(){
		return {
			sid:''
		}
	},
    created(){
		this.login()
	},
	methods:{
		host(url){
			return  "http://card.adouyun.com/CloudCard/"+url+".shtml";
		},
		getData(data){
			var userInfo={
				sid:this.sid,
				username:data.user.crealname,
				uid:data.user.id,
				info:data.infos
			}
			this.$store.commit('saveUserInfo',userInfo)
			sessionStorage.setItem('sid',this.sid);
			sessionStorage.setItem('shareName',data.user.crealname);
			// sessionStorage.setItem('username',data.user.crealname);
			// sessionStorage.setItem('uid',data.user.id);
			// // var headimg=data.data.user.cheadimage
			// // sessionStorage.setItem('uimg',headimg);
			// var infostring=JSON.stringify(data.infos)
			// sessionStorage.setItem('userinfos',infostring);
			let url=sessionStorage.getItem('curl') ? sessionStorage.getItem('curl') : '/';
			this.$router.replace({path:url})
		},
		login() {
			var qs = require('qs');
			this.sid=this.GetQueryString('sessionid')
			// var subscribe=this.GetQueryString('subscribe')
			// sessionStorage.setItem('subscribe',subscribe);
			var  sendjson={
				sessionid: this.sid,
			}
			this.$http.post(this.host('user/ssoLogin'),qs.stringify(sendjson))
			.then((response)=>{
				var data=response.data
				if(data.result==1){
					var curData=data.data
					this.getData(curData)
				}
			})
		}
	}
}
</script>